package structural_pattern.composite_pattern;

import java.util.ArrayList;

public class Folder extends AbstractFile{

    private String name;
    //定义集合fileList，用于存储AbstractFile类型的成员
    private ArrayList<AbstractFile> fileArrayList = new ArrayList<>();

    public Folder(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile file) {
        fileArrayList.add(file);
    }

    @Override
    public void remove(AbstractFile file) {
        fileArrayList.remove(file);
    }

    @Override
    public AbstractFile getChild(int i) {
        return fileArrayList.get(i);
    }

    @Override
    public void killVirus() {
//模拟杀毒
        System.out.println("*****对文件夹"+name+"进行杀毒");
        //递归调用成员构件的killVirus方法
        for (AbstractFile abstractFile : fileArrayList) {
            abstractFile.killVirus();
        }
    }
}
